home *** CD-ROM | disk | FTP | other *** search
- /**************************************************************************
- * obput.c: Main program for ObPut.
- * Send Oberheim patch data from a file to the synth.
- * A part of OberSuite for the Commodore Amiga.
- *
- * Author: Daniel Barrett, barrett@cs.umass.edu.
- * Version: 1.0.
- * Copyright: None! This program is in the Public Domain.
- * Please share it with others.
- ***************************************************************************/
-
- #include "decl.h"
- #include "obput.h"
-
- char *version = "$VER: ObPut " VERSION " " VERDATE;
-
- /***************************************************************************
- * The main program.
- ***************************************************************************/
-
- main(argc, argv)
- int argc; char *argv[];
- {
- Enable_Abort = 0; /* Disable ^C aborts. */
- strcpy(programName, BaseName(argv[0])); /* Global variable. */
- thePrintStyle = VERBOSE; /* Global variable. */
-
-
- if (argc == 1)
- {
- ShortUsageMsg();
- BegForUsage();
- }
- else if ((argc == 2) && (!strcmp(argv[1], "?")))
- DetailedUsage();
- else if (!HandleOptions(argc, argv))
- BegForUsage();
- else if (optind == argc-1)
- ObPut(NULL, argv[optind]);
- else if (optind == argc-2)
- ObPut(argv[optind], argv[optind+1]);
- else
- ErrorMsg(ERROR_NUMARGS);
-
- exit(0);
- }
-
-
- /*
- * Send the data in the given file to the given patch location (specified
- * in patchString).
- */
-
- void ObPut(char *patchString, char *filename)
- {
- PATCHINFO pi;
-
- InitPatchInfo(&pi);
- pi.source = PI_SOURCE_FILE;
- if (!SerialSetup())
- return;
-
- if (BreakUp(patchString, &pi))
- {
- if (!LookAtFileSize(&pi, filename))
- ;
- else if (!TransmitPatchInfo(&pi, filename))
- ErrorMsg(ERROR_FAILED);
- else
- ;
- }
-
- SerialShutdown();
- FreePatchInfo(&pi);
- }
-
-
- /*
- * Interpret the string "patchString" and store the appropriate data in
- * the given PATCHINFO structure.
- * If the patchString is empty, we will send the data to the patch whose
- * number is already embedded in the patch data in the file.
- * Otherwise, patchString MUST be an integer between FIRST_PATCH and
- * LAST_PATCH, inclusive. Store the integer in the patchNum field.
- * Return TRUE on success (else FALSE).
- */
-
- BOOL BreakUp(char *patchString, PATCHINFO *pi)
- {
- if (!patchString)
- {
- pi->patchNum = DEFAULT_PATCH_NUM;
- return(TRUE);
- }
- else if (AllDigits(patchString))
- {
- pi->patchNum = (UBYTE)(atoi(patchString));
- if (!Between(pi->patchNum, FIRST_PATCH, LAST_PATCH))
- {
- ErrorMsg(ERROR_PATCHNUM);
- return(FALSE);
- }
- else
- return(TRUE);
- }
- else
- {
- ErrorMsg(ERROR_PATCHNUM);
- return(FALSE);
- }
- }
-
-
- /***************************************************************************
- * Handle the command-line options.
- ***************************************************************************/
-
- BOOL HandleOptions(int argc, char *argv[])
- {
- int c;
- short printed = 0; /* How many print options were chosen? */
-
- while ((c = getopt(argc, argv, options)) != EOF)
- {
- switch (c)
- {
- case OPT_SILENT:
- thePrintStyle = SILENT;
- printed++;
- break;
- case OPT_VERBOSE:
- thePrintStyle = VERBOSE;
- printed++;
- break;
- case OPT_DEADQUIET:
- thePrintStyle = DEADQUIET;
- printed++;
- break;
- default:
- return(FALSE);
- }
- }
-
- if (printed > 1) /* Can't choose >1 print option. */
- ErrorMsg(ERROR_TWOPRINTS);
-
- return(printed <= 1);
- }
-
-
- /***************************************************************************
- * Transmit the patch data from the given file to MIDI.
- * Return success or failure.
- ***************************************************************************/
-
- BOOL TransmitPatchInfo(PATCHINFO *pi, char *filename)
- {
- BOOL result = TRUE;
-
- if (! (result = AllocPatchInfo(pi)) )
- ErrorMsg(ERROR_MALLOC);
- else if (! (result = GetPatchFromFile(pi, filename)) )
- ErrorMsg(ERROR_GETFAILED);
- else if (! (result = PutPatchToMidi(pi)) )
- ErrorMsg(ERROR_PUTFAILED_SEND);
-
- return(result);
- }
-
-
- /***************************************************************************
- * Usage information.
- ***************************************************************************/
-
-
- void ShortUsageMsg(void)
- {
- if (!ERR_OUTPUT_ALLOWED)
- return;
-
- fprintf(stderr, "Usage: %s [options] [PatchNumber] filename\n",
- programName);
- }
-
-
- void UsageMsg(void)
- {
- if (!ERR_OUTPUT_ALLOWED)
- return;
-
- fprintf(stderr, "%s sends Xpander/Matrix-12 patch data from a"
- " file to the synthesizer.\n",
- programName);
-
- ShortUsageMsg();
-
- fprintf(stderr, "\nLegal options are:\n");
- fprintf(stderr, "\t-%c:\tQuiet output; error messages only.\n",
- OPT_SILENT);
- fprintf(stderr, "\t-%c:\tNo output; not even error messages.\n",
- OPT_DEADQUIET);
- fprintf(stderr, "\t-%c:\tLong output. (DEFAULT)\n",
- OPT_VERBOSE);
-
- fprintf(stderr, "\nIf you specify a patch number (%d-%d),"
- " your data is sent to that patch\n"
- "location. Otherwise, the data is sent to its"
- " original patch location.\n",
- FIRST_PATCH, LAST_PATCH);
-
- fprintf(stderr, "If the file contains more than 1 patch, "
- "any \"PatchNumber\" parameter will\nbe ignored.\n");
-
- fprintf(stderr, "\nExamples:\n");
- fprintf(stderr, "\t%s -%c 23 myPatchFile\n", programName,
- OPT_VERBOSE);
- fprintf(stderr, "\t%s myPatchFile\n", programName);
- }
-
-
- char *Version(void)
- {
- static char v[] = VERSION;
- return(v);
- }
-